<?php
/**
 * 拜访， 
 * 张名尊，20140508
 */ 


class visitAction extends backendAction{
    
    public function _initialize() {
        parent::_initialize();
        $this->_mod = D('visit');
        $this->attrbuteType = 'visit';
    }    
    
    public function _before_index(){
        $this->list_relation = true;
    }
    
    public function _after_index(){

    }
    

    /**
     * 搜索
     */ 
    protected function _search() {
        $map = array();
        ($time_start = $this->_request('time_start', 'trim')) && $map['v'][] = array('egt', $time_start);
        ($time_end = $this->_request('time_end', 'trim')) && $map['date'][] = array('elt', $time_end);
        $cateId = $this->_request('cateId');
        if ($cateId) {
            list($regionId,$storeId) = explode('_',$cateId);

            $regionList = F('region_list');
            $region = $regionList['l'][$regionId];
            $id_arr = D('region')->get_child_ids($cateId, true);
            $id_arr = implode(',',$id_arr);
            if(!empty($id_arr)){
               // $this->_mod->setStoreLinkCondition("regionId in ('$id_arr')");
            }
            $spids = $region['spid'];
            //var_dump($spids,$regionId,$storeId);
            //exit();            
            if(!$spids){
                $spids = $regionId;
            }else{
                $spids .=$regionId.'|';
            }
            if(!empty($storeId)){
                $map['storeId'] =$storeId;
                $spids.=$regionId.'_'.$storeId.'|';
            }
        }
        $this->assign('search', array(
            'time_start' => $time_start,
            'time_end' => $time_end,
            'selected_ids' => $spids,
            'cateId'=>$cateId,
        ));
        return $map;
    }




    
    /**
     * 这里会显示巡检的详细信息
     */ 
    public function show(){
        $id = $this->_request('id');
        $id = intval($id);
        $info = $this->_mod->relation(true)->where(array('id'=>$id))->find();
        $info['images'] = unserialize($info['images']);
        $info['images'] = $info['images']['image'];
        //属性列表
        $attrilist = D('attribute')->getAttribute($this->attrbuteType);
        //print_r($attrilist);
        $this->assign('attrilist',$attrilist);     
        //这是属性的值       
        $attrValue = D('attribute')->getAttributeValue($this->attrbuteType,$id);   
        $this->assign('attrValue',$attrValue); 
        //print_r($attrValue);             
        $this->assign('info',$info); 
        $this->display();
    }
    
    
    
}






?>